$(function () {

    //获取用户信息
    const getUserDate = () => {
        ajax('GET', 'http://localhost:8080/api/v1/admin/user/detail', {}, (res) => {
            $('#username').val(res.data.username)
            $('#nickname').val(res.data.nickname)
            $('#email').val(res.data.email)
            $('.user_pic').prop('src', res.data.userPic)
            $('#password').val(res.data.password)
        })
    }
    getUserDate()

    //用户图标
    $('#exampleInputFile').on('change', function () {
        const url = URL.createObjectURL(this.files[0])
        $('.user_pic').prop('src', url)
    })

    //使用formData提交修改后的用户信息
    $('form').on('submit', function (e) {
        e.preventDefault()
        const fd = new FormData(this)
        fd.forEach(function (value, key) {
            console.log({ value, key });

        })
        ajax('POST', 'http://localhost:8080/api/v1/admin/user/edit', fd, (res) => {
            console.log(res);

            layer.msg(res.msg, {
                icon: 1,
                time: 2000,
            });
        })
    })

})